#!/usr/bin/python3
import tushare as ts
import json
import matplotlib.pyplot as plt

def obj_to_Json(obj):
    data = json.dumps(obj, indent=4,ensure_ascii=False)
    fh = open('data.json', 'w')
    fh.write(data)
    fh.close()  # 最终写入的json文件格式:

#print(ts.__version__)
#ts.set_token('dfeb543866c1b2b3e804f3cbed560e9e1709b0d06cd8182e1cc5676d')
pro = ts.pro_api('ea3263c5424f08c3e04d605af9458cfc349613d5b7c27e99994eb396')
#ts_pro.get_hist_data('601318') 
start='20220101'
end='20220301'
# 中国平安 代替 Tesla at p78
zgpa_df = pro.daily(ts_code='601318.SH', start_date=start, end_date=end)
#print(zgpa_df.head())
#print(type(zgpa_df))
import matplotlib.pyplot as plt
zgpa_df[['trade_date','close','vol']].plot(x='trade_date',subplots=True, style=['r','g'],grid=True)
plt.show()